package com.itbaizhan.rocketmqdemo.producer;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
//延迟消息生产者
public class DelayMessageProducer {

    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        //创建生产组
        DefaultMQProducer producer = new DefaultMQProducer("producer_group_02");
        producer.setNamesrvAddr("192.168.66.100:9876");
        producer.start();

        //定义message对象
        Message message = null;
        for(int i=0;i<20;i++){
            message=new Message("topic_demo_01",("hello rocketmq delayMessage -"+i).getBytes());
            //设置延迟时间 0-17，0表示不延迟  1表示延迟2秒  大于18都是延迟2小时
            message.setDelayTimeLevel(i);
            producer.send(message);
        }
        producer.shutdown();
    }
}

